import 'package:dio_wrapper/dio_wrapper.dart';

class ApiCostInterceptor extends Interceptor {
  final Map<RequestOptions, int> _costDuration = {};

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    _costDuration[options] = DateTime.now().millisecondsSinceEpoch;
    super.onRequest(options, handler);
  }

// @override
// void onResponse(Response response, ResponseInterceptorHandler handler) {
//   int? start = _costDuration[response.requestOptions];
//   if (null != start) {
//     int cost = DateTime.now().millisecondsSinceEpoch - start;
//     debugPrint("cost: ${cost}ms");
//   }
// 这里一定要调用父方法，否则response不走了
//   super.onResponse(response, handler);
// }
}
